home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / CullGroupSample / Source / QD3D_Support.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  17.9 KB  |  636 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*       QD3D SUPPORT.C        */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /****************************/
  8. /*    EXTERNALS             */
  9. /****************************/
  10. #include <NumberFormatting.h>
  11.  
  12. #include <QD3D.h>
  13. #include <QD3DGroup.h>
  14. #include <QD3DLight.h>
  15. #include <QD3DTransform.h>
  16. #include <QD3DStorage.h>
  17. #include <QD3DMath.h>
  18. #include <QD3DErrors.h>
  19.  
  20. #include <timer.h>
  21. #include "myglobals.h"
  22. #include "misc.h"
  23. #include "qd3d_support.h"
  24. #include "mywindows.h"
  25.  
  26. extern    short                gHtab;
  27. extern    WindowPtr            gModelWindow;
  28.  
  29.  
  30. /****************************/
  31. /*    PROTOTYPES            */
  32. /****************************/
  33.  
  34. static void CreateDrawContext(QD3DViewDefType *viewDefPtr);
  35. static void SetStyles(QD3DStyleDefType *styleDefPtr);
  36. static void CreateCamera(QD3DCameraDefType *cameraDefPtr);
  37. static void CreateLights(QD3DLightDefType *lightDefPtr);
  38. static void CreateView(QD3DSetupInputType *setupDefPtr);
  39. static void CreateTexturePixmap(PicHandle pict,unsigned long mapSizeX,
  40.                              unsigned long mapSizeY, TQ3CompressedPixmap *bMap);
  41. static void TraverseDisplayGroupInfo(TQ3Object theGroup);
  42. static void ShowMeshInfo(TQ3Object theMesh);
  43. static void ShowAttributeInfo(TQ3AttributeSet theAttribute);
  44. static void ShowTriMeshInfo(TQ3Object theTriMesh);
  45.  
  46.  
  47. /****************************/
  48. /*    CONSTANTS             */
  49. /****************************/
  50.  
  51.  
  52. /*********************/
  53. /*    VARIABLES      */
  54. /*********************/
  55.  
  56. static TQ3CameraObject            gQD3D_CameraObject;
  57. static TQ3GroupObject            gQD3D_LightGroup;
  58. static TQ3ViewObject            gQD3D_ViewObject;
  59. static TQ3DrawContextObject        gQD3D_DrawContext;
  60. static TQ3RendererObject        gQD3D_RendererObject;
  61. static TQ3ShaderObject            gQD3D_ShaderObject;
  62. static    TQ3StyleObject            gQD3D_BackfacingStyle;
  63. static    TQ3StyleObject            gQD3D_FillStyle;
  64. static    TQ3StyleObject            gQD3D_InterpolationStyle;
  65.  
  66. float    gFramesPerSecond = DEFAULT_FPS;                // this is used to maintain a constant timing velocity as frame rates differ
  67.  
  68.  
  69.  
  70. //=======================================================================================================
  71. //=============================== VIEW WINDOW SETUP STUFF ===============================================
  72. //=======================================================================================================
  73.  
  74.  
  75. /************** SETUP QD3D WINDOW *******************/
  76.  
  77. void QD3D_SetupWindow(QD3DSetupInputType *setupDefPtr, QD3DSetupOutputType *outputPtr)
  78. {
  79.     CreateView(setupDefPtr);
  80.     Q3InteractiveRenderer_SetDoubleBufferBypass(gQD3D_RendererObject,kQ3True);        // let hardware go fast    
  81.     CreateCamera(&setupDefPtr->camera);                                        // create new CAMERA object
  82.     CreateLights(&setupDefPtr->lights);
  83.     SetStyles(&setupDefPtr->styles);    
  84.     
  85.  
  86.                 /* DISPOSE OF EXTRA REFERENCES */
  87.                 
  88.     Q3Object_Dispose(gQD3D_RendererObject);                // (is contained w/in gQD3D_ViewObject)
  89.  
  90.     
  91.                 /* PASS BACK INFO */
  92.                 
  93.     outputPtr->viewObject = gQD3D_ViewObject;
  94.     outputPtr->interpolationStyle = gQD3D_InterpolationStyle;
  95.     outputPtr->fillStyle = gQD3D_FillStyle;
  96.     outputPtr->backfacingStyle = gQD3D_BackfacingStyle;
  97.     outputPtr->shaderObject = gQD3D_ShaderObject;
  98.     outputPtr->cameraObject = gQD3D_CameraObject;
  99.     outputPtr->lightGroup = gQD3D_LightGroup;
  100.     outputPtr->drawContext = gQD3D_DrawContext;
  101.     outputPtr->window = setupDefPtr->view.displayWindow;        // remember which window
  102.     outputPtr->paneClip = setupDefPtr->view.paneClip;
  103. }
  104.  
  105.  
  106. /***************** QD3D_DisposeWindowSetup ***********************/
  107. //
  108. // Disposes of all data created by QD3D_SetupWindow
  109. //
  110.  
  111. void QD3D_DisposeWindowSetup(QD3DSetupOutputType *data)
  112. {
  113.     Q3Object_Dispose(data->viewObject);
  114.     Q3Object_Dispose(data->interpolationStyle);
  115.     Q3Object_Dispose(data->backfacingStyle);
  116.     Q3Object_Dispose(data->fillStyle);
  117.     Q3Object_Dispose(data->cameraObject);
  118.     Q3Object_Dispose(data->lightGroup);
  119.     Q3Object_Dispose(data->drawContext);
  120.     Q3Object_Dispose(data->shaderObject);
  121. }
  122.  
  123.  
  124. /******************* CREATE GAME VIEW *************************/
  125.  
  126. static void CreateView(QD3DSetupInputType *setupDefPtr)
  127. {
  128. TQ3Status    myErr;
  129. unsigned long    hints;
  130.  
  131.                 /* CREATE NEW VIEW OBJECT */
  132.                 
  133.     gQD3D_ViewObject = Q3View_New();
  134.     if (gQD3D_ViewObject == nil)
  135.         DoFatalAlert("\pQ3View_New failed!");
  136.  
  137.  
  138.             /* CREATE & SET DRAW CONTEXT */
  139.     
  140.     CreateDrawContext(&setupDefPtr->view);                                 // init draw context
  141.     
  142.     myErr = Q3View_SetDrawContext(gQD3D_ViewObject, gQD3D_DrawContext);            // assign context to view
  143.     if (myErr == kQ3Failure)
  144.         DoFatalAlert("\pQ3View_SetDrawContext Failed!");
  145.  
  146.  
  147.  
  148.             /* CREATE & SET RENDERER */
  149.  
  150.     gQD3D_RendererObject = Q3Renderer_NewFromType(setupDefPtr->view.rendererType);    // create new RENDERER object
  151.     if (gQD3D_RendererObject == nil)
  152.     {
  153.         QD3D_ShowError("\pQ3Renderer_NewFromType Failed!", true);
  154.         CleanQuit();
  155.     }
  156.  
  157.     myErr = Q3View_SetRenderer(gQD3D_ViewObject, gQD3D_RendererObject);                // assign renderer to view
  158.     if (myErr == kQ3Failure)
  159.         DoFatalAlert("\pQ3View_SetRenderer Failed!");
  160.  
  161.         /* SET RENDERER FEATURES */
  162.         
  163.     Q3InteractiveRenderer_GetRAVEContextHints(gQD3D_RendererObject, &hints);
  164.     hints &= ~kQAContext_NoZBuffer;                 // Z buffer is on 
  165.     hints &= ~kQAContext_DeepZ;                     // Z buffer is not deep, ergo it's shallow 
  166.     hints |= kQAContext_NoDither;                     // No Dither 
  167.     Q3InteractiveRenderer_SetRAVEContextHints(gQD3D_RendererObject, hints);    
  168.     
  169.     Q3InteractiveRenderer_SetRAVETextureFilter(gQD3D_RendererObject,kQATextureFilter_Mid);    // fast texturing
  170.     Q3InteractiveRenderer_SetDoubleBufferBypass(gQD3D_RendererObject,kQ3True);
  171. }
  172.  
  173.  
  174. /**************** CREATE SKELETON DRAW CONTEXT *********************/
  175.  
  176. static void CreateDrawContext(QD3DViewDefType *viewDefPtr)
  177. {
  178. TQ3DrawContextData        drawContexData;
  179. TQ3MacDrawContextData    myMacDrawContextData;
  180. Rect                    r;
  181.  
  182.     r = viewDefPtr->displayWindow->portRect;
  183.  
  184.  
  185.             /* FILL IN DRAW CONTEXT DATA */
  186.  
  187.     drawContexData.clearImageMethod = kQ3ClearMethodWithColor;                // how to clear
  188.     drawContexData.clearImageColor = viewDefPtr->clearColor;                // color to clear to
  189.     drawContexData.pane.min.x = r.left+viewDefPtr->paneClip.left;            // set bounds?
  190.     drawContexData.pane.max.x = r.right-viewDefPtr->paneClip.right;
  191.     drawContexData.pane.min.y = r.top+viewDefPtr->paneClip.top;
  192.     drawContexData.pane.max.y = r.bottom-viewDefPtr->paneClip.bottom;
  193.     drawContexData.paneState = kQ3True;                                        // use bounds?
  194.     drawContexData.maskState = kQ3False;                                    // no mask
  195.     drawContexData.doubleBufferState = kQ3True;                                // double buffering
  196.  
  197.     myMacDrawContextData.drawContextData = drawContexData;                    // set MAC specifics
  198.     myMacDrawContextData.window = (CWindowPtr)viewDefPtr->displayWindow;    // assign window to draw to
  199.     myMacDrawContextData.library = kQ3Mac2DLibraryNone;                        // use standard QD libraries (no GX crap!)
  200.     myMacDrawContextData.viewPort = nil;                                    // (for GX only)
  201.     myMacDrawContextData.grafPort = (CWindowPtr)viewDefPtr->displayWindow;    // assign grafport
  202.  
  203.  
  204.             /* CREATE DRAW CONTEXT */
  205.  
  206.     gQD3D_DrawContext = Q3MacDrawContext_New(&myMacDrawContextData);
  207.     if (gQD3D_DrawContext == nil)
  208.         DoFatalAlert("\pQ3MacDrawContext_New Failed!");
  209. }
  210.  
  211.  
  212. /**************** SET STYLES ****************/
  213. //
  214. // Creates style objects which define how the scene is to be rendered.
  215. // It also sets the shader object.
  216. //
  217.  
  218. static void SetStyles(QD3DStyleDefType *styleDefPtr)
  219. {
  220.  
  221.                 /* SET INTERPOLATION (FOR SHADING) */
  222.                     
  223.     gQD3D_InterpolationStyle = Q3InterpolationStyle_New(styleDefPtr->interpolation);
  224.     if (gQD3D_InterpolationStyle == nil)
  225.         DoFatalAlert("\pQ3InterpolationStyle_New Failed!");
  226.  
  227.                     /* SET BACKFACING */
  228.  
  229.     gQD3D_BackfacingStyle = Q3BackfacingStyle_New(styleDefPtr->backfacing);
  230.     if (gQD3D_BackfacingStyle == nil )
  231.         DoFatalAlert("\pQ3BackfacingStyle_New Failed!");
  232.  
  233.  
  234.                 /* SET POLYGON FILL STYLE */
  235.                         
  236.     gQD3D_FillStyle = Q3FillStyle_New(styleDefPtr->fill);
  237.     if ( gQD3D_FillStyle == nil )
  238.         DoFatalAlert("\p Q3FillStyle_New Failed!");
  239.  
  240.  
  241.                     /* SET THE SHADER TO USE */
  242.  
  243.     switch(styleDefPtr->illuminationType)
  244.     {
  245.         case    kQ3IlluminationTypePhong:
  246.                 gQD3D_ShaderObject = Q3PhongIllumination_New();
  247.                 if ( gQD3D_ShaderObject == nil )
  248.                     DoFatalAlert("\p Q3PhongIllumination_New Failed!");
  249.                 break;
  250.                 
  251.         case    kQ3IlluminationTypeLambert:
  252.                 gQD3D_ShaderObject = Q3LambertIllumination_New();
  253.                 if ( gQD3D_ShaderObject == nil )
  254.                     DoFatalAlert("\p Q3LambertIllumination_New Failed!");
  255.                 break;
  256.                 
  257.         case    kQ3IlluminationTypeNULL:
  258.                 gQD3D_ShaderObject = Q3NULLIllumination_New();
  259.                 if ( gQD3D_ShaderObject == nil )
  260.                     DoFatalAlert("\p Q3NullIllumination_New Failed!");
  261.                 break;
  262.     }    
  263. }
  264.  
  265.  
  266.  
  267. /****************** CREATE CAMERA *********************/
  268.  
  269. static void CreateCamera(QD3DCameraDefType *cameraDefPtr)
  270. {
  271. TQ3CameraData                    myCameraData;
  272. TQ3ViewAngleAspectCameraData    myViewAngleCameraData;
  273. TQ3Area                            pane;
  274. TQ3Status                        status;
  275. TQ3Status    myErr;
  276.  
  277.     status = Q3DrawContext_GetPane(gQD3D_DrawContext,&pane);                // get window pane info
  278.     if (status == kQ3Failure)
  279.         DoFatalAlert("\pQ3DrawContext_GetPane Failed!");
  280.  
  281.  
  282.                 /* FILL IN CAMERA DATA */
  283.                 
  284.     myCameraData.placement.cameraLocation = cameraDefPtr->from;            // set camera coords
  285.     myCameraData.placement.pointOfInterest = cameraDefPtr->to;            // set target coords
  286.     myCameraData.placement.upVector = cameraDefPtr->up;                    // set a vector that's "up"
  287.     myCameraData.range.hither = cameraDefPtr->hither;                    // set frontmost Z dist
  288.     myCameraData.range.yon = cameraDefPtr->yon;                            // set farthest Z dist
  289.     myCameraData.viewPort.origin.x = -1.0;                                // set view origins?
  290.     myCameraData.viewPort.origin.y = 1.0;
  291.     myCameraData.viewPort.width = 2.0;
  292.     myCameraData.viewPort.height = 2.0;
  293.  
  294.     myViewAngleCameraData.cameraData = myCameraData;
  295.     myViewAngleCameraData.fov = cameraDefPtr->fov;                        // larger = more fisheyed
  296.     myViewAngleCameraData.aspectRatioXToY =
  297.                 (pane.max.x-pane.min.x)/(pane.max.y-pane.min.y);
  298.  
  299.     gQD3D_CameraObject = Q3ViewAngleAspectCamera_New(&myViewAngleCameraData);     // create new camera
  300.     if (gQD3D_CameraObject == nil)
  301.         DoFatalAlert("\pQ3ViewAngleAspectCamera_New failed!");
  302.         
  303.     myErr = Q3View_SetCamera(gQD3D_ViewObject, gQD3D_CameraObject);        // assign camera to view
  304.     if (myErr == kQ3Failure)
  305.         DoFatalAlert("\pQ3View_SetCamera Failed!");
  306.  
  307. }
  308.  
  309.  
  310. /********************* CREATE LIGHTS ************************/
  311.  
  312. static void CreateLights(QD3DLightDefType *lightDefPtr)
  313. {
  314. TQ3GroupPosition        myGroupPosition;
  315. TQ3LightData            myLightData;
  316. TQ3DirectionalLightData    myDirectionalLightData;
  317. TQ3LightObject            myLight;
  318. short                    i;
  319. TQ3Status    myErr;
  320.  
  321.  
  322.             /* CREATE NEW LIGHT GROUP */
  323.             
  324.     gQD3D_LightGroup = Q3LightGroup_New();                        // make new light group
  325.     if ( gQD3D_LightGroup == nil )
  326.         DoFatalAlert("\p Q3LightGroup_New Failed!");
  327.  
  328.  
  329.     myLightData.isOn = kQ3True;                                    // light is ON
  330.     
  331.             /************************/
  332.             /* CREATE AMBIENT LIGHT */
  333.             /************************/
  334.  
  335.     if (lightDefPtr->ambientBrightness != 0)                        // see if ambient exists
  336.     {
  337.         myLightData.color = lightDefPtr->ambientColor;                // set color of light
  338.         myLightData.brightness = lightDefPtr->ambientBrightness;    // set brightness value
  339.         myLight = Q3AmbientLight_New(&myLightData);                    // make it
  340.         if ( myLight == nil )
  341.             DoFatalAlert("\pQ3AmbientLight_New Failed!");
  342.  
  343.         myGroupPosition = Q3Group_AddObject(gQD3D_LightGroup, myLight);    // add to group
  344.         if ( myGroupPosition == 0 )
  345.             DoFatalAlert("\p Q3Group_AddObject Failed!");
  346.  
  347.         Q3Object_Dispose(myLight);                                    // dispose of light
  348.  
  349.     }
  350.  
  351.             /**********************/
  352.             /* CREATE FILL LIGHTS */
  353.             /**********************/
  354.             
  355.     for (i=0; i < lightDefPtr->numFillLights; i++)
  356.     {        
  357.         myLightData.color = lightDefPtr->fillColor[i];                        // set color of light
  358.         myLightData.brightness = lightDefPtr->fillBrightness[i];            // set brightness
  359.         myDirectionalLightData.lightData = myLightData;                        // refer to general light info
  360.         myDirectionalLightData.castsShadows = kQ3False;                        // no shadows
  361.         myDirectionalLightData.direction =  lightDefPtr->fillDirection[i];    // set fill vector
  362.         myLight = Q3DirectionalLight_New(&myDirectionalLightData);            // make it
  363.         if ( myLight == nil )
  364.             DoFatalAlert("\p Q3DirectionalLight_New Failed!");
  365.  
  366.         myGroupPosition = Q3Group_AddObject(gQD3D_LightGroup, myLight);        // add to group
  367.         if ( myGroupPosition == 0 )
  368.             DoFatalAlert("\p Q3Group_AddObject Failed!");
  369.  
  370.         Q3Object_Dispose(myLight);                                            // dispose of light
  371.     }
  372.     
  373.             /* ASSIGN LIGHT GROUP TO VIEW */
  374.             
  375.     myErr = Q3View_SetLightGroup(gQD3D_ViewObject, gQD3D_LightGroup);        // assign light group to view
  376.     if (myErr == kQ3Failure)
  377.         DoFatalAlert("\pQ3View_SetLightGroup Failed!");        
  378.  
  379. }
  380.  
  381. /******************** QD3D CHANGE DRAW SIZE *********************/
  382. //
  383. // Changes size of stuff to fit new window size.
  384. //
  385.  
  386. void QD3D_ChangeDrawSize(QD3DSetupOutputType *setupInfo)
  387. {
  388. Rect            r;
  389. TQ3Area            pane;
  390. TQ3ViewAngleAspectCameraData    cameraData;
  391.  
  392.             /* CHANGE DRAW CONTEXT PANE SIZE */
  393.             
  394.     r = setupInfo->window->portRect;                            // get size of window
  395.     pane.min.x = r.left+setupInfo->paneClip.left;                                        // set pane size
  396.     pane.max.x = r.right-setupInfo->paneClip.right;
  397.     pane.min.y = r.top+setupInfo->paneClip.top;
  398.     pane.max.y = r.bottom-setupInfo->paneClip.bottom;
  399.     Q3DrawContext_SetPane(setupInfo->drawContext,&pane);        // update pane in draw context
  400.  
  401.  
  402.                 /* CHANGE CAMERA ASPECT RATIO */
  403.                 
  404.     Q3ViewAngleAspectCamera_GetData(setupInfo->cameraObject,&cameraData);            // get camera data
  405.     cameraData.aspectRatioXToY = (pane.max.x-pane.min.x)/(pane.max.y-pane.min.y);    // set new aspect ratio
  406.     Q3ViewAngleAspectCamera_SetData(setupInfo->cameraObject,&cameraData);            // set new camera data
  407. }
  408.  
  409.  
  410. /******************* QD3D DRAW SCENE *********************/
  411.  
  412. void QD3D_DrawScene(QD3DSetupOutputType *setupInfo, void (*drawRoutine)(QD3DSetupOutputType *))
  413. {
  414. TQ3Status                myStatus;
  415. TQ3ViewStatus            myViewStatus;
  416.  
  417.             /* START RENDERING */
  418.  
  419. //startTrace("test.tt6");
  420.  
  421.     myStatus = Q3View_StartRendering(setupInfo->viewObject);            
  422.     if ( myStatus == kQ3Failure )
  423.     {
  424.         DoFatalAlert("\p Q3View_StartRendering Failed!");
  425.     }
  426.     
  427.             /***************/
  428.             /* RENDER LOOP */
  429.             /***************/
  430.     do
  431.     {
  432.                 /* DRAW STYLES */
  433.                 
  434.         myStatus = Q3Style_Submit(setupInfo->interpolationStyle,setupInfo->viewObject);
  435.         if ( myStatus == kQ3Failure )
  436.             DoFatalAlert("\p Q3Style_Submit Failed!");
  437.             
  438.         myStatus = Q3Style_Submit(setupInfo->backfacingStyle,setupInfo->viewObject);
  439.         if ( myStatus == kQ3Failure )
  440.             DoFatalAlert("\p Q3Style_Submit Failed!");
  441.             
  442.         myStatus = Q3Style_Submit(setupInfo->fillStyle, setupInfo->viewObject);
  443.         if ( myStatus == kQ3Failure )
  444.             DoFatalAlert("\p Q3Style_Submit Failed!");
  445.  
  446.         myStatus = Q3Shader_Submit(setupInfo->shaderObject, setupInfo->viewObject);
  447.         if ( myStatus == kQ3Failure )
  448.             DoFatalAlert("\p Q3Shader_Submit Failed!");
  449.  
  450.  
  451.             /* CALL INPUT DRAW FUNCTION */
  452.  
  453.         drawRoutine(setupInfo);
  454.  
  455.         myViewStatus = Q3View_EndRendering(setupInfo->viewObject);
  456.         
  457.     } while ( myViewStatus == kQ3ViewStatusRetraverse );
  458.     
  459. //stopTrace();
  460. //CleanQuit();
  461. }
  462.  
  463.  
  464. //=======================================================================================================
  465. //=============================== MISC ==================================================================
  466. //=======================================================================================================
  467.  
  468. /************** QD3D CALC FRAMES PER SECOND *****************/
  469.  
  470. float    QD3D_CalcFramesPerSecond(void)
  471. {
  472. UnsignedWide    wide;
  473. unsigned long    now;
  474. static    unsigned long then = 0;
  475.  
  476.     Microseconds(&wide);
  477.     now = wide.lo;
  478.     if (then != 0)
  479.     {
  480.         gFramesPerSecond = (double)1000000.0/(double)(now-then);
  481.         if (gFramesPerSecond < DEFAULT_FPS)            // (avoid divide by 0's later)
  482.             gFramesPerSecond = DEFAULT_FPS;
  483.     
  484.     }
  485.     else
  486.         gFramesPerSecond = DEFAULT_FPS;
  487.         
  488. #if 1
  489. //        if (GetKeyState(KEY_SHIFT))
  490.         {
  491.             Str255            s;
  492.                 
  493.             SetPort(gModelWindow);
  494.             FloatToString(gFramesPerSecond,s);    // print # rounded up to nearest integer
  495.             MoveTo(20,20);
  496.             ForeColor(whiteColor);
  497.             BackColor(blackColor);
  498.             TextSize(16);
  499.             TextFace(bold);
  500.             TextMode(srcCopy);
  501.             DrawString(s);
  502.             DrawChar(' ');
  503.         }
  504. #endif
  505.         
  506.         
  507.     then = now;                                // remember time    
  508.     
  509.     return(gFramesPerSecond);
  510. }
  511.  
  512.  
  513.  
  514. #pragma mark ========== error stuff ===========
  515.  
  516.  
  517. /******************* QD3D: SHOW ERROR *************************/
  518. //
  519. // Returns true if Error, false if just a warning.
  520. //
  521.  
  522. Boolean QD3D_ShowError(Str255 errString, Boolean showWarnings)
  523. {
  524. TQ3Error    err;
  525. TQ3Warning    warning;
  526. Str255        numStr;
  527.  
  528.         /* DO ERRORS */
  529.         
  530.     err = Q3Error_Get(nil);
  531.     if (err != 0)
  532.     {
  533.         DoAlert(errString);
  534.         switch(err)
  535.         {
  536.             case    kQ3ErrorViewNotStarted:
  537.                     DoFatalAlert("\pError:kQ3ErrorViewNotStarted");
  538.                     break;
  539.                     
  540.             case    kQ3ErrorOutOfMemory:
  541.                     DoFatalAlert("\pError:kQ3ErrorOutOfMemory");
  542.                     break;
  543.                     
  544.             default:
  545.                     ShowSystemErr(err);
  546.         }
  547.         return(true);
  548.     }
  549.     
  550.         /* DO WARNINGS */
  551.     else
  552.     {
  553.         if (!showWarnings)
  554.             return(false);
  555.         
  556.         DoAlert(errString);
  557.         warning = Q3Warning_Get(nil);
  558.         switch(warning)
  559.         {
  560.             case    kQ3WarningFunctionalityNotSupported:
  561.                     DoAlert("\pWarning: kQ3WarningFunctionalityNotSupported");
  562.                     break;
  563.                     
  564.             default:
  565.                     NumToString(err, numStr);
  566.                     DoAlert (numStr);
  567.         }
  568.         return(false);
  569.     }
  570.     
  571.     
  572. }
  573.  
  574.  
  575. /************ QD3D: SHOW RECENT ERROR *******************/
  576.  
  577. void QD3D_ShowRecentError(void)
  578. {
  579. TQ3Error    q3Err;
  580. Str255        s;
  581.     
  582.     q3Err = Q3Error_Get(nil);
  583.     if (q3Err == kQ3ErrorOutOfMemory)
  584.         QD3D_DoMemoryError();
  585.     else
  586.     if (q3Err == kQ3ErrorMacintoshError)
  587.         DoFatalAlert("\pkQ3ErrorMacintoshError");
  588.     else
  589.     if (q3Err != 0)
  590.     {
  591.         NumToString(q3Err,s);
  592.         DoFatalAlert(s);
  593.     }
  594. }
  595.  
  596. /***************** QD3D: DO MEMORY ERROR **********************/
  597.  
  598. void QD3D_DoMemoryError(void)
  599. {
  600.     InitCursor();
  601.     NoteAlert(129,nil);
  602.     CleanQuit();
  603. }
  604.  
  605.  
  606. #pragma mark ============ CAMERA STUFF ==================
  607.  
  608.  
  609.  
  610. /*************** QD3D_UpdateCameraFrom ***************/
  611.  
  612. void QD3D_UpdateCameraFrom(QD3DSetupOutputType *setupInfo, TQ3Point3D *from)
  613. {
  614. TQ3Status    status;
  615. TQ3CameraPlacement    placement;
  616.  
  617.             /* GET CURRENT CAMERA INFO */
  618.             
  619.     status = Q3Camera_GetPlacement(setupInfo->cameraObject, &placement);
  620.     if (status == kQ3Failure)
  621.         DoFatalAlert("\pQ3Camera_GetPlacement failed!");
  622.  
  623.  
  624.             /* SET CAMERA COORDS */
  625.             
  626.  
  627.     placement.cameraLocation = *from;
  628.     
  629.  
  630.             /* UPDATE CAMERA INFO */
  631.             
  632.     status = Q3Camera_SetPlacement(setupInfo->cameraObject, &placement);
  633.     if (status == kQ3Failure)
  634.         DoFatalAlert("\pQ3Camera_SetPlacement failed!");
  635. }
  636.